package com.company.project.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.company.project.common.config.HealthConfig;
import com.company.project.common.utils.DateUtils;
import com.company.project.service.HealthCertificateInquiryService;
import com.company.project.vo.req.HealthCertificateQueryVO;
import com.company.project.vo.resp.HealthCertificateQueryResultDTO;
import com.company.project.vo.resp.HealthCertificateResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.thymeleaf.util.StringUtils;
import springfox.documentation.spring.web.json.Json;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author liuhui
 */
@Slf4j
@Service
public class HealthCertificateInquiryServiceImpl implements HealthCertificateInquiryService {
    private static final String INTERFACE_METHOD = "/api/exchange/findJkz";
    @Resource
    private HealthConfig healthConfig;

    @Override
    public List<HealthCertificateQueryResultDTO> healthCertificate(HealthCertificateQueryVO queryVO) {
        String result = sendMessage(JSON.toJSONString(queryVO),healthConfig.getUrl() + INTERFACE_METHOD);
        log.info("查询参数返回：参数：{}，返回数据：{}",JSON.toJSONString(queryVO),result);
        return null;
    }

    private String sendMessage(String params, String url) {
        log.info("上传参数={}", params);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
        HttpEntity<MultiValueMap<String, String>> request = new HttpEntity(params, headers);
        RestTemplate restTemplate = new RestTemplate();
        String result = restTemplate.postForEntity(url, request, String.class).getBody();
        log.info("上传结果={}", result);
        return result;
    }
}
